var si = require('systeminformation');
var utils = require("./utils");

si.networkInterfaceDefault(function (data) {
    console.log(data);
});

var netData = [Array(61).fill(0), Array(61).fill(0)];

console.log("==========");
si.networkInterfaceDefault(function (iface) {
    setInterval(() => {
        // this.defaultIface = iface;
        si.networkStats(iface, data => {
            var rx_sec = Math.max(0, data['rx_sec']);
            var tx_sec = Math.max(0, data['tx_sec']);

            netData[0].shift();
            netData[0].push(rx_sec);

            netData[1].shift();
            netData[1].push(tx_sec);

            rx_label = 'Receiving:      ' +
                utils.humanFileSize(rx_sec) +
                '/s \nTotal received: ' +
                utils.humanFileSize(data['rx']);

            tx_label = 'Transferring:      ' +
                utils.humanFileSize(tx_sec) +
                '/s \nTotal transferred: ' +
                utils.humanFileSize(data['tx']);

            console.log([rx_label, tx_label]);
            console.log(netData);
        });

    }, 1000);
});